﻿using System.Web;

public class AppHelper
{
    public static string PhotoRoot = "~/photos/";
    public static string CacheDirctory = "_cache";
    public static string SvnDirectory = ".svn";

    /// <summary>
    /// Builds an Image URL
    /// </summary>
    /// <param name="imageFile">The file name of the image</param>
    public static string ImageUrl(string imageFile)
    {
        return VirtualPathUtility.ToAbsolute("~/content/images/" + imageFile);
    }

    /// <summary>
    /// Returns a cache directory for a folder's photos
    /// </summary>
    /// <param name="directory">Directory containing photos</param>
    public static string ImageCache(string directory)
    {
        return directory + "/" + CacheDirctory;
    }

    /// <summary>
    /// Builds a name for a photo's thumbnail
    /// </summary>
    /// <param name="photoName">File name of the photo</param>
    public static string Thumbnail(string photoName)
    {
        return "t_" + photoName;
    }

    /// <summary>
    /// Builds a name for a photo's display image
    /// </summary>
    /// <param name="photoName">File name of the photo</param>
    public static string DisplayImage(string photoName)
    {
        return "d_" + photoName;
    }

    /// <summary>
    /// Builds a CSS URL
    /// </summary>
    /// <param name="cssFile">The name of the CSS file</param>
    public static string CssUrl(string cssFile)
    {
        return VirtualPathUtility.ToAbsolute("~/content/css/" + cssFile);
    }

    /// <summary>
    /// Buils a Photo URL
    /// </summary>
    /// <param name="photoDirectory">The photo directory</param>
    /// <param name="photoName">File name of the photo</param>
    public static string PhotoUrl(string photoDirectory, string photoName)
    {
        return VirtualPathUtility.ToAbsolute(PhotoRoot + photoDirectory + "/" + photoName);
    }

    public static string ThumbUrl(string photoDirectory, string photoName)
    {
        return VirtualPathUtility.ToAbsolute(PhotoRoot + ImageCache(photoDirectory) + "/" + Thumbnail(photoName));
    }

    public static string DisplayImageUrl(string photoDirectory, string photoName)
    {
        return VirtualPathUtility.ToAbsolute(PhotoRoot + photoDirectory + "/" + photoName);
    }

    /// <summary>
    /// Cleans up a URL so it looks pretty for search engines
    /// </summary>
    /// <param name="url">The string to be URLified</param>
    /// <returns>A pretty URL string</returns>
    public static string ToCleanUrl(string url)
    {
        return url.Replace(" ", "+");
    }

    /// <summary>
    /// Cleans up a URL so it looks pretty for search engines
    /// </summary>
    /// <param name="url">The string to be URLified</param>
    /// <returns>A pretty URL string</returns>
    public static string FromCleanUrl(string url)
    {
        return url.Replace("+", " ");
    }

    public static string SeoName(string url)
    {
        return url.Replace(" - ", "-").Replace("  ", "-").Replace("&", "-").Replace(" ", "-").Replace("*", "-").Replace("%", "-");
    }
}